﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DAO;
using DTO;
using BUS;

namespace QuanLyKhachSan
{
    public partial class TraCuuPhong : Form
    {
        public TraCuuPhong()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Chắc chắn muốn thoát ???", "Warning !!!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                this.Close();
        }

        private void buttonTraCuuCB_Click(object sender, EventArgs e)
        {
            //lvDSPhong.Items.Clear();
            //string tenPhong = txtTenPhong.Text;
            //string loaiPhong = txtLoaiPhong.Text;
            //List<PhongDTO> dsSinhVien = PhongBUS.layDSPhongTheoYeuCau(tenPhong, loaiPhong);
            //for (int i = 0; i < dsSinhVien.Count; i++)
            //{
            //    ListViewItem LVI = new ListViewItem(new String[] { (i + 1).ToString(), dsSinhVien[i].TenPhong, dsSinhVien[i].LoaiPhong.TenLoaiPhong, dsSinhVien[i].LoaiPhong.DonGia.ToString(), dsSinhVien[i].TinhTrang.ToString() });
            //    lvDSPhong.Items.Add(LVI);
            //}
            lvDSPhong.Items.Clear();
            List<PhongDTO> dsPhong = PhongBUS.layDSPhong();
            for (int i = 0; i < dsPhong.Count; i++)
            {
                if (cbTenPhong.Checked == true)
                {
                    if (dsPhong[i].TenPhong.ToLower().Contains(txtTenPhong.Text.ToLower()) == false)
                    {
                        dsPhong.RemoveAt(i);
                        i--;
                        continue;
                    }
                }
                if (cbLoaiPhong.Checked == true)
                {
                    if (comboBoxLoaiPhong.Text != dsPhong[i].LoaiPhong.TenLoaiPhong)
                    {
                        dsPhong.RemoveAt(i);
                        i--;
                        continue;
                    }
                }

                if (cbTinhTrang.Checked == true)
                {
                    if (comboBoxTinhTrang.Text != dsPhong[i].TinhTrang.ToString())
                    {
                        dsPhong.RemoveAt(i);
                        i--;
                        continue;
                    }
                }
            }
            for (int i = 0; i < dsPhong.Count; i++)
            {
                ListViewItem item = new ListViewItem(new string[] { (i+1).ToString(), dsPhong[i].TenPhong, dsPhong[i].LoaiPhong.TenLoaiPhong, dsPhong[i].DonGia.DonGia.ToString(), dsPhong[i].TinhTrang.ToString()});
                lvDSPhong.Items.Add(item);
            }
        }

        private void TraCuuPhong_Load(object sender, EventArgs e)
        {
            List<LoaiPhongDTO> dsLoaiPhong = LoaiPhongBUS.layDSLoaiPhong();
            for (int i = 0; i < dsLoaiPhong.Count; i++)
            {
                comboBoxLoaiPhong.Items.Add(dsLoaiPhong[i].TenLoaiPhong);
            }
        }

    }
}
